using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ImPM.Data.ManagerObjects;
using ImPM.Data.BusinessObjects;
using ImPM.Data.Base;

namespace ImPM.Data.UnitTests
{
	[TestFixture]
    public partial class RiskTests : UNuitTestBase
    {
        protected IRiskManager manager;
		
		public RiskTests()
        {
            manager = managerFactory.GetRiskManager();
        }
		
		protected Risk CreateNewRisk()
		{
			Risk entity = new Risk();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = 81;
			
			entity.RiskName = "Test Test Test Test Test Test Test ";
			entity.DueDate = DateTime.Now;
			entity.UserIDOwner = 20;
			entity.CreatedDate = DateTime.Now;
			entity.Decription = "Test Test ";
			entity.Probablity = 87;
			entity.Mitigation = "Test Test ";
			entity.UserIDAssignedTo = 15;
			entity.TaskID = 56;
			entity.status = 21;
			entity.RiskType = default(SByte);
			
			return entity;
		}
		protected Risk GetFirstRisk()
        {
            IList<Risk> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Risk entity = CreateNewRisk();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Risk entityA = CreateNewRisk();
				manager.Save(entityA);

                Risk entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Risk entityA = GetFirstRisk();
				entityA.RiskName = "Test Test Test Test Test Test Test Test Test";
				
				manager.Update(entityA);

                Risk entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.RiskName, entityB.RiskName);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Risk entity = GetFirstRisk();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}